#include "njm_ecs.hpp"

namespace njm
{
    Coordinator::Coordinator()
    {
        Init();
    }
    Coordinator::~Coordinator()
    {
    }

    void Coordinator::Init()
    {
        mComponentManager = std::make_unique<ComponentManager>();
        mEntityManager = std::make_unique<EntityManager>();
        mSystemManager = std::make_unique<SystemManager>();
    }
    void Coordinator::Clear()
    {
        mComponentManager->Clear();
        mEntityManager->Clear();
        mSystemManager->Clear();
    }
    // 
    void Coordinator::Update(float deltaTime)
    {
        mSystemManager->Update(deltaTime, *this);
    }

    // Entity 相关方法
    Entity Coordinator::CreateEntity()
    {
        return mEntityManager->CreateEntity();
    }

    std::vector<Entity> Coordinator::CreateEntities(int count)
    {
        std::vector<Entity> entities;
        for (int i = 0; i < count; i++)
        {
            entities.push_back(mEntityManager->CreateEntity());
        }
        return entities;
    }

    void Coordinator::DestroyEntity(Entity entity)
    {
        mEntityManager->DestroyEntity(entity);
        mComponentManager->EntityDestroyed(entity);
        mSystemManager->EntityDestroyed(entity);
    }

}
